'use strict'
const path = require('path');
const webpack = require('webpack');
const devUrl = 'http://10.10.0.3:9992'
const testUrl = 'http://10.10.0.3:9994'
// const local = 'http://10.10.0.54:9082'
const local = 'http://192.168.20.69:9082'
// const local = 'http://10.10.3.17:9082'

const baseUrl = local

function resolve(dir) {
	return path.join(__dirname, dir)
}

module.exports = {
	publicPath: './',
	outputDir: 'system-management-web',
	assetsDir: 'static', // 静态目录
	chainWebpack(config) { // svg
		config.plugins.delete('prefetch') // 移除prefetch插件
		config.module
			.rule('svg')
			.exclude.add(resolve('src/icons'))
			.end()
		config.module
			.rule('icons')
			.test(/\.svg$/)
			.include.add(resolve('src/icons'))
			.end()
			.use('svg-sprite-loader')
			.loader('svg-sprite-loader')
			.options({
				symbolId: 'icon-[name]'
			})
			.end()
		config.plugin('provide').use(webpack.ProvidePlugin, [{
			'_': 'underscore'
		}])
	},
	css: {
		// 是否使用css分离插件 ExtractTextPlugin
		extract: false,
		// 开启 CSS source maps?
		sourceMap: false,
		// 启用 CSS modules for all css / pre-processor files.
		modules: false
	},
	productionSourceMap: false, // 生产环境下是否产生map
	// configureWebpack: config => {
	// 	if (process.env.NODE_ENV === 'production') { // 生产环境
	// 	} else if (process.env.NODE_ENV === 'test') { // 测试环境
	// 	} else { // 开发环境
	// 	}
	// },
	devServer: {
		port: 8088,
		proxy: {
			'/uploads': {
				target: 'http://192.168.20.56:8080',
				changeOrigin: true,
				ws: true,
				pathRewrite: {
					'^/uploads': ''
				}
			},

			'/filesAdminUrl': { // 文件管理
				target: 'http://10.10.0.200:9992/fastdfs',
				// target: 'http://192.168.20.56:8084',
				// target: 'http://192.168.20.60:8084',
				changeOrigin: true,
				ws: true,
				pathRewrite: {
					'^/filesAdminUrl': ''
				}
			},
			'/filesSpecialUrl': { // 文件管理上传加zzul
				target: 'http://10.10.0.200:9992/zuul/fastdfs',
				// target: 'http://192.168.20.56:8084',
				changeOrigin: true,
				ws: true,
				pathRewrite: {
					'^/filesSpecialUrl': ''
				}
			},
			
			'/dataSourceUrl': { // 数据源
				target: 'http://10.10.0.200:9992/data-source-service/api',
				changeOrigin: true,
				ws: true,
				pathRewrite: {
					'^/dataSourceUrl': ''
				}
			},
			'/xd_cloud_dictionary': { // 数据字典
				target: 'http://10.10.0.200:9992/xd-cloud-dictionary/api',
				changeOrigin: true,
				ws: true,
				pathRewrite: {
					'^/xd_cloud_dictionary': ''
				}
			},
			'/dataaccess': { // 进度条
				target: 'http://10.10.0.200:9992/dataaccess/api',
				changeOrigin: true,
				ws: true,
				pathRewrite: {
					'^/dataaccess': ''
				}
			},
			'/userAdminUrl': { // 用户管理
				// target: `${baseUrl}/system-management/api`,
				target: `${baseUrl}/api`,
				changeOrigin: true,
				ws: true,
				pathRewrite: {
					'^/userAdminUrl': ''
				}
			},
			'/datacenter-permission': {
				// target: `${baseUrl}/system-management`,
				target: `${baseUrl}`,
				changeOrigin: true,
				ws: true,
				pathRewrite: {
					'^/datacenter-permission': ''
				}
			}
		}
	},
}